package com.example.sherlockzhong.plush_v2.Utils;

/*
 * Created by DosonLeung on 2014/8/13.
 */

import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.TranslateAnimation;

public class AnimationUtil {
    public static Animation generateFlyInAnimation(int duration, String direction) {
        float x = 0.0f;
        float y = 0.0f;
        String[] directions = direction.split("-");
        if (directions.length > 1) {
            if (directions[1].equalsIgnoreCase("left")) {
                x = -1.0f;
            } else if (directions[1].equalsIgnoreCase("top")) {
                y = -1.0f;
            } else if (directions[1].equalsIgnoreCase("right")) {
                x = 1.0f;
            } else if (directions[1].equalsIgnoreCase("bottom")) {
                y = 1.0f;
            }
        }
        if (directions[0].equalsIgnoreCase("left")) {
            x = -1.0f;
        } else if (directions[0].equalsIgnoreCase("top")) {
            y = -1.0f;
        } else if (directions[0].equalsIgnoreCase("right")) {
            x = 1.0f;
        } else if (directions[0].equalsIgnoreCase("bottom")) {
            y = 1.0f;
        }
        TranslateAnimation animation = new
                TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, x,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, y,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        animation.setInterpolator(new DecelerateInterpolator());
        animation.setDuration(duration);
        return animation;
    }

    public static Animation generateFlyOutAnimation(int duration, String direction) {
        float x = 0.0f;
        float y = 0.0f;
        String[] directions = direction.split("-");
        if (directions.length > 1) {
            if (directions[1].equalsIgnoreCase("left")) {
                x = -1.0f;
            } else if (directions[1].equalsIgnoreCase("top")) {
                y = -1.0f;
            } else if (directions[1].equalsIgnoreCase("right")) {
                x = 1.0f;
            } else if (directions[1].equalsIgnoreCase("bottom")) {
                y = 1.0f;
            }
        }
        if (directions[0].equalsIgnoreCase("left")) {
            x = -1.0f;
        } else if (directions[0].equalsIgnoreCase("top")) {
            y = -1.0f;
        } else if (directions[0].equalsIgnoreCase("right")) {
            x = 1.0f;
        } else if (directions[0].equalsIgnoreCase("bottom")) {
            y = 1.0f;
        }
        TranslateAnimation animation = new
                TranslateAnimation(
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, x,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, y);
        animation.setInterpolator(new AccelerateInterpolator());
        animation.setDuration(duration);
        return animation;
    }


}
